package com.zx.util;

import java.io.InputStream;
import java.io.PrintWriter;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;


public class ResponseUtil {

    public static void write(HttpServletResponse response, String text) throws Exception {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.println(text);
        out.flush();
        out.close();
    }

    public static void write(HttpServletResponse response, InputStream in, String mimeType) throws Exception {
        ServletOutputStream out = response.getOutputStream();

        byte[] b = new byte[1024];
        int len = 0;
        while ((len = in.read(b)) != -1) {
            out.write(b, 0, len);
        }
        out.flush();
        out.close();
    }


}
